package com.pet.server.ext.action.user;

import java.util.Date;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.VerificationCode;
import com.pet.server.ext.service.SystemService;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.DateUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;
public class Updateprofile extends ActionBase{
	
	public String sex,nick_name,ico_path,background;
	public String type;
	public VerificationCode vcode = null;
	public Updateprofile(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {
		type = params.getFieldValue("type");
		if("ico".equals(type)){
			ico_path = params.getFileUrl("ico_path");
			if(StringUtil.isEmpty(ico_path)){
				throw ApiError.Type.INVALID_PARAM.toException();
			}
		}else if("background".equals(type)){
			background = params.getFileUrl("background");
			if(StringUtil.isEmpty(background)){
				throw ApiError.Type.INVALID_PARAM.toException();
			}
		}else if("sex".equals(type)){
			sex = params.getFieldValue("sex");
			if(StringUtil.isEmpty(sex)){
				throw ApiError.Type.INVALID_PARAM.toException();
			}
		}else if("nickname".equals(type)){
			nick_name = params.getFieldValue("nick_name");
			if(StringUtil.isEmpty(nick_name)){
				throw ApiError.Type.INVALID_PARAM.toException();
			}
		}else{
            
			throw ApiError.Type.INVALID_PARAM.toException();
		}
		
		
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		if("ico".equals(type)){
			userService.updateIcoPath(ico_path, user.user_id);
			data.put("message", "修改头像成功!");
		}else if("background".equals(type)){
			userService.updateBackground(background, user.user_id);
			data.put("message", "修改背景墙成功!");
		}else if("sex".equals(type)){
			userService.updateSex(sex, user.user_id);
			data.put("message", "修改性别成功!");
		}else if("nickname".equals(type)){
			userService.updateNickname(nick_name, user.user_id);
			data.put("message", "修改昵称成功!");
		}
		Result result = new Result();
		result.put("data", data);
	    return result;
	}
	
	
}
